package com.example.webwork.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.example.webwork.entity.User;
import com.example.webwork.mapper.UserMapper;
import com.example.webwork.service.IUserService;
import com.sun.tools.jconsole.JConsoleContext;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.UUID;

@Service("UserServiceImpl")
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    public User getUserById(Long id){
        // todo 补充实现逻辑，拦截器只查询拦截，update，在这里直接选好要进行怎么改
        //分库分表

        if (id % 2 == 0) {
            if(id%4==0)
            return UserMapper.getUserByIdFromDb0_user1(id);
            else
                return UserMapper.getUserByIdFromDb0_user0(id);
        } else {
            if (id % 4 == 0)
            return UserMapper.getUserByIdFromDb1_user1(id);
            else
                return UserMapper.getUserByIdFromDb1_user0(id);
        }

    }

    public User insertUser(User user){
        // todo 补充实现逻辑
        //insert会被拦截,拦截器直接实现了，在拦截器里，判断去的库和表
        return UserMapper.save(user);


    }

    public List<User> getUserByEmail(String email){
        // 仔细思考如何实现

        //一张一张表查,搞个假id，1，2，3，4
        for(int i=1;i<=4;i++)
        {

        }


    }
}